package com.zy.cat.common.utils;

import org.jasypt.encryption.StringEncryptor;
import org.jasypt.encryption.pbe.PooledPBEStringEncryptor;
import org.jasypt.encryption.pbe.config.SimpleStringPBEConfig;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 配置文件信息加密
 * 
 * @author Link
 * @date 2019-02-25 11:57
 */
@Configuration
public class Encryptor {
	 @Bean("jasyptStringEncryptor")
	    public StringEncryptor stringEncryptor() {
	        PooledPBEStringEncryptor encryptor = new PooledPBEStringEncryptor();
	        SimpleStringPBEConfig config = new SimpleStringPBEConfig();
	        config.setPassword("zy-mall*#$&^!125478KIJHY2354!");
	        config.setAlgorithm("PBEWithMD5AndDES");
	        config.setKeyObtentionIterations("1000");
	        config.setPoolSize("100");
	        config.setProviderName("SunJCE");
	        config.setSaltGeneratorClassName("org.jasypt.salt.RandomSaltGenerator");
	        config.setStringOutputType("base64");
	        encryptor.setConfig(config);
	        return encryptor;
	    }
	 
	 public static void main(String[] args) {
		 Encryptor e=new Encryptor();
		 String cl=e.stringEncryptor().encrypt("zy_mall_connect*#123");
		 String dcl=e.stringEncryptor().decrypt(cl);
		 System.out.println("---->"+cl);
		 System.out.println("---->"+dcl);
		 
	}
}
